package com.five.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.five.pojo.ClubPeople;
import com.five.pojo.PageBean;
import com.five.pojo.Result;
import com.five.service.ClubPeopleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lenovo
 */
@Tag(name = "社团成员接口")
@RestController
@CrossOrigin
@RequestMapping("/ClubPeople")
public class ClubPeopleController {
    @Autowired
    ClubPeopleService clubPeopleService;
    //通过社团查询成员
    @Operation(summary = "通过社团查询成员")
    @GetMapping("/findBycClub")
    public Result find(String cClub){
        List<ClubPeople> clubPeople = clubPeopleService.findBycClub(cClub);
        return Result.success(clubPeople);
    }

    //管理员/社长移除社团成员
    @Operation(summary = "管理员移除社团成员(管理员)")
    @DeleteMapping("{id}")
    public Result delete(@RequestParam Integer id){
        clubPeopleService.deleteById(id);
        return Result.success();
    }
    //管理员/团长添加社团成员
    @Operation(summary = "管理员/团长添加社团成员")
    @PostMapping("/addStudent")
    public Result addStudent(@RequestBody ClubPeople clubPeople){
        clubPeopleService.addStudent(clubPeople);
        return Result.success();
    }

    //分页条件查询所有
    @Operation(summary = "社团成员分页查询")
    @GetMapping("/page")
    public Result pageSelect(@RequestParam(defaultValue = "1") Integer pageNumber ,
                             @RequestParam(defaultValue = "5") Integer pageSize ,
                             String cClub , String sName){
        PageBean pageBean = clubPeopleService.page(pageNumber , pageSize , cClub , sName);
        return Result.success(pageBean);
    }
}
